package com.ruoyi.interfaceConfig.sceneConfig.service.impl;

import java.util.List;

import com.ruoyi.interfaceConfig.sceneConfig.domain.dto.FieldMappingDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.interfaceConfig.sceneConfig.mapper.FieldMappingMapper;
import com.ruoyi.interfaceConfig.sceneConfig.domain.FieldMapping;
import com.ruoyi.interfaceConfig.sceneConfig.service.IFieldMappingService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 字段映射关系Service业务层处理
 * 
 * @author YiYuan
 * @date 2024-02-22
 */
@Service
@RequiredArgsConstructor
public class FieldMappingServiceImpl implements IFieldMappingService 
{
    private final FieldMappingMapper fieldMappingMapper;

    /**
     * 查询字段映射关系
     * 
     * @param id 字段映射关系主键
     * @return 字段映射关系
     */
    @Override
    public FieldMapping selectFieldMappingById(Long id)
    {
        return fieldMappingMapper.selectFieldMappingById(id);
    }

    /**
     * 查询字段映射关系列表
     * 
     * @param fieldMapping 字段映射关系
     * @return 字段映射关系
     */
    @Override
    public List<FieldMapping> selectFieldMappingList(FieldMapping fieldMapping)
    {
        return fieldMappingMapper.selectFieldMappingList(fieldMapping);
    }

    /**
     * 新增字段映射关系
     * 
     * @param fieldMapping 字段映射关系
     * @return 结果
     */
    @Override
    public int insertFieldMapping(FieldMapping fieldMapping)
    {
        return fieldMappingMapper.insertFieldMapping(fieldMapping);
    }

    /**
     * 修改字段映射关系
     * 
     * @param fieldMapping 字段映射关系
     * @return 结果
     */
    @Override
    public int updateFieldMapping(FieldMapping fieldMapping)
    {
        return fieldMappingMapper.updateFieldMapping(fieldMapping);
    }

    /**
     * 批量删除字段映射关系
     * 
     * @param ids 需要删除的字段映射关系主键
     * @return 结果
     */
    @Override
    public int deleteFieldMappingByIds(Long[] ids)
    {
        return fieldMappingMapper.deleteFieldMappingByIds(ids);
    }

    /**
     * 删除字段映射关系信息
     * 
     * @param id 字段映射关系主键
     * @return 结果
     */
    @Override
    public int deleteFieldMappingById(Long id)
    {
        return fieldMappingMapper.deleteFieldMappingById(id);
    }

    /**
     * 保存字段映射关系
     * @param fieldMappingDTO
     * @return
     */
    @Override
    @Transactional
    public int saveFieldMapping(FieldMappingDTO fieldMappingDTO) {
        //删除场景sceneId的映射信息
        Long sceneId = fieldMappingDTO.getSceneId();
        List<FieldMapping> fieldMappingList = fieldMappingDTO.getFieldMappingList();
        fieldMappingMapper.deleteFieldMappingBySceneId(sceneId);
        //保存映射关系
        int row = fieldMappingMapper.insertBatch(sceneId, fieldMappingList);
        return row;
    }
}
